package com.ruoyi.common.utils.android;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.uuid.UUID;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

public class Post {

    private Map<String, String> a() {

        HashMap<String,String> hashMap = new HashMap();
        hashMap.put("os", "1");
        hashMap.put("qdid", "50");
        hashMap.put("uid", "17679946");//element,17679946
        hashMap.put("token", "a5930ef64db8e6de99cca977ca43a407");//token，ba5cfc0bb2d5288a903df13c021bd688，a5930ef64db8e6de99cca977ca43a407
        hashMap.put("sensor", "0");
        hashMap.put("app_model", "2");//app_model
        hashMap.put("versionCode", "115");
        hashMap.put("ver", "1");
        JSONObject jSONObject = new JSONObject();
        String uuid = UUID.getRandom().toString();
        jSONObject.put("system", "android10");
        jSONObject.put("cpu", "arm64-v8a");
        jSONObject.put("deviceId", uuid);
        jSONObject.put("phoneName", "TFY HONOR");
        jSONObject.put("deviceName", "TFY-AN00");
        jSONObject.put("ram", "3.56 GB");
        jSONObject.put("metrics", "1080*2289");
        jSONObject.put("operator", "");
        jSONObject.put("netType", "NR");
        hashMap.put("phoneMsg", jSONObject.toJSONString());
        return hashMap;
    }

    public String a(JSONObject jSONObject) {
        Map<String, String> map = a();
        try {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                String key = entry.getKey();
                if (!jSONObject.containsKey(key)) {
                    jSONObject.put(key, (Object) entry.getValue());
                }
            }
            String json = jSONObject.toJSONString();
            System.out.println("json: " + json);
            String encrypt = DecryptString.getInstance().encrypt(json);
            return "data=" + encrypt + "&sign=" + encrypt2MD5(encrypt + "79dd2c687a1ff0ef20839cf402d6c468");
        } catch (Exception unused2) {
            unused2.printStackTrace();
            return "";
        }
    }

    public static String encrypt2MD5(String str) {
        try {
            byte[] digest = MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8"));
            StringBuilder sb = new StringBuilder(digest.length * 2);
            for (byte b : digest) {
                int i = b & 255;
                if (i < 16) {
                    sb.append("0");
                }
                sb.append(Integer.toHexString(i));
            }
            return sb.toString();
        } catch (UnsupportedEncodingException e2) {
            throw new RuntimeException("Huh, UTF-8 should be supported?", e2);
        } catch (NoSuchAlgorithmException e3) {
            throw new RuntimeException("Huh, MD5 should be supported?", e3);
        }
    }


}
